package control;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.User;
public class EditUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public EditUser() {
        super();
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		String lv = request.getParameter("lv");
		String uid = request.getParameter("uid");
		User u = new User();
		if (!u.isUID(uid)) {
			request.setAttribute("m", "err-eu");
			request.setAttribute("r","vu");
			RequestDispatcher transferexist = getServletContext().getRequestDispatcher("/a/message.jsp");
			transferexist.forward(request, response);
		} else {
			if(u.upDateLV(uid,lv)==false){
			request.setAttribute("m", "err-eu");
			request.setAttribute("r","vu");
			RequestDispatcher transfer = getServletContext().getRequestDispatcher("/a/message.jsp");
			transfer.forward(request, response);
			}
			else{
				request.setAttribute("m", "edit-uok");
				request.setAttribute("r","vu");
				RequestDispatcher transfer = getServletContext().getRequestDispatcher("/a/message.jsp");
				transfer.forward(request, response);
			}
		}
	}
	
}
